package com.nabicht.bigblankpage.gui;

import java.awt.Color;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;

import javax.swing.JFrame;
import javax.swing.JPanel;

public class BBPFrame extends JFrame {

	private BBPDocument document = null;
	
	public BBPFrame() {
		this(null);
	}
	
	public BBPFrame(final BBPDocument doc) {
		
		setBackground(Color.BLACK);	//TODO have this set as a preference
		
		setDocument(doc);
		
		//TODO something better than this, like save the document
		addWindowListener(new WindowAdapter() {
			public void windowClosing(WindowEvent e) {
				if (document != null) {
					document.save();
				}
			}
		});
	}
	
	public void setDocumentName(String docName) {
		/*the doc name doesn't need to be kept anywhere because 
		 * it is reflected in the gui but not state that needs to be kept here
		 */
		setTitle(docName);
	}
	
	public void setDocument(BBPDocument doc) {
		this.document = doc;
		if (document == null) {
			setContentPane(new JPanel());
		} else {
			setContentPane(document.getPanel());
		}
		//getContentPane().repaint();
		setEnabled(doc == null ? false : true);
		repaint();
	}
	

}
